package com.pureut.scheduling.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.scheduling.domain.SchedulingCalendar;
import com.pureut.scheduling.domain.dto.CalendarSpecialDto;
import com.pureut.scheduling.domain.dto.SchedulingCalendarDto;
import com.pureut.scheduling.domain.dto.ShopCalendarDto;
import com.pureut.scheduling.domain.vo.CalendarSpecialVo;
import com.pureut.scheduling.domain.vo.SchedulingCalendarVo;
import com.pureut.scheduling.service.ISchedulingCalendarService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * @Description 工厂日历控制层
 * @Date 22-12-29
 * @Author hl
 **/
@RestController
@RequestMapping("/shopCalendar")
public class SchedulingCalendarController extends BaseController {

    @Resource
    private ISchedulingCalendarService schedulingCalendarService;

    /**
     * 查询工厂日历
     */
    @RequiresPermissions("schedule:scheduleConfig:shopCalendar:list")
    @GetMapping("/list")
    public TableDataInfo list(SchedulingCalendarVo schedulingCalendarVo)
    {
        startPage();
        List<SchedulingCalendarDto> list = schedulingCalendarService.selectCalendarList(schedulingCalendarVo);
        return getDataTable(list);
    }

    /**
     * 新增工厂日历
     */
    @RequiresPermissions("schedule:scheduleConfig:shopCalendar:add")
    @Log(title = "工厂日历", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SchedulingCalendar schedulingCalendar) throws Exception {
        return toAjax(schedulingCalendarService.insertSchedulingCalendar(schedulingCalendar));
    }

    /**
     * 批量删除工厂日历
     */
    @RequiresPermissions("schedule:scheduleConfig:shopCalendar:remove")
    @Log(title = "工厂日历", businessType = BusinessType.DELETE)
    @DeleteMapping("/{calendarId}")
    public AjaxResult remove(@PathVariable("calendarId") String calendarId){
        return toAjax(schedulingCalendarService.deleteCalendarById(calendarId));
    }

    /**
     * 根据编号获取详细信息
     */
    @RequiresPermissions("schedule:scheduleConfig:shopCalendar:query")
    @GetMapping(value = "/{calendarId}")
    public AjaxResult getInfo(@PathVariable long calendarId)
    {
        return AjaxResult.success(schedulingCalendarService.selectCalendarById(calendarId));
    }

    /**
     * 修改工厂日历
     */
    @RequiresPermissions("schedule:scheduleConfig:shopCalendar:edit")
    @Log(title = "工厂日历", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody SchedulingCalendar schedulingCalendar) throws Exception{
        return toAjax(schedulingCalendarService.updateCalendarEdit(schedulingCalendar));
    }

    /**
     * 新增特殊日历
     */
    @RequiresPermissions("schedule:scheduleConfig:shopCalendar:addSpecial")
    @Log(title = "工厂日历", businessType = BusinessType.INSERT)
    @PostMapping("/addSpecial")
    public AjaxResult addSpecial(@Validated @RequestBody CalendarSpecialVo calendarSpecialVo) throws Exception {
        return toAjax(schedulingCalendarService.insertCalendarSpecia(calendarSpecialVo));
    }

    /**
     * 查询特殊工厂日历
     */
    //@RequiresPermissions("schedule:scheduleConfig:shopCalendar:listSpecial")
    @GetMapping("/listSpecial")
    public TableDataInfo listSpecial(CalendarSpecialVo calendarSpecialVo)
    {
        startPage();
        List<CalendarSpecialDto> list = schedulingCalendarService.selectCalendarSpecialList(calendarSpecialVo);
        return getDataTable(list);
    }

    /**
     * 批量删除特殊日历
     */
   // @RequiresPermissions("schedule:scheduleConfig:shopCalendar:removeSpecial")
    @Log(title = "工厂日历", businessType = BusinessType.DELETE)
    @DeleteMapping("/delSpecial")
    public AjaxResult delSpecial(String calendarId) throws Exception{
        return toAjax(schedulingCalendarService.deleteCalendarSpecialById(calendarId));
    }

    /**
     * 修改特殊日历
     */
    //@RequiresPermissions("schedule:scheduleConfig:shopCalendar:editSpecial")
    @Log(title = "工厂日历", businessType = BusinessType.UPDATE)
    @PutMapping("/editSpecial")
    public AjaxResult editSpecial(@RequestBody CalendarSpecialVo calendarSpecialVo) throws Exception{
        return toAjax(schedulingCalendarService.updateCalendarSpecialEdit(calendarSpecialVo));
    }

    /**
     * 根据Id查询单个特殊日历
     */
   // @RequiresPermissions("schedule:scheduleConfig:shopCalendar:getInfoSpecial")
    @GetMapping("/getInfoSpecial")
    public AjaxResult getInfoSpecial(long calendarId)
    {
        return AjaxResult.success(schedulingCalendarService.selectCalendarSpecialById(calendarId));
    }

    /**
     * 日历查看
     */
    //@RequiresPermissions("schedule:scheduleConfig:shopCalendar:CalendarViewing")
    @GetMapping("/viewing")
    public AjaxResult CalendarViewing(int year, int month,long lineId)  throws IOException{
        if(lineId==0){
            return AjaxResult.success(0);
        }
        return AjaxResult.success(schedulingCalendarService.selectCalendarViewing(year,month,lineId));
    }

    /**
     * 班组管理工厂日历下拉菜单
     */
    @GetMapping("/selectShopCalendarList")
    public TableDataInfo selectShopCalendarList(CalendarSpecialVo calendarSpecialVo)
    {
        List<ShopCalendarDto> shopCalendarDtos = schedulingCalendarService.selectShopCalendarList(calendarSpecialVo);
        return getDataTable(shopCalendarDtos);
    }

    /**
     * 根据工厂日历id查询班组
     */
    @GetMapping("/selectShiftCalendarList")
    public AjaxResult selectShiftCalendarList(long calendarId)
    {
        return AjaxResult.success(schedulingCalendarService.selectShiftCalendarList(calendarId));
    }

    /**
     * 根据工厂日历id查询线别
     */
    @GetMapping("/selectLineTypeCalendarList")
    public AjaxResult selectLineTypeCalendarList(long calendarId)
    {
        return AjaxResult.success(schedulingCalendarService.selectLineTypeCalendarList(calendarId));
    }

    /**
     * 根据工厂日历id查询班别信息
     */
    @GetMapping("/selectShiftSettingList/{calendarId}")
    public AjaxResult selectShiftSettingList(@PathVariable("calendarId") long calendarId)
    {
        return AjaxResult.success(schedulingCalendarService.selectShiftSettingList(calendarId));
    }

    /**
     * 根据线别查询班次信息
     */
    @GetMapping("/selectShiftLine/{lineCode}")
    public AjaxResult selectShiftLine(@PathVariable("lineCode") String lineCode)
    {
        return AjaxResult.success(schedulingCalendarService.selectShiftLine(lineCode));
    }


}
